package com.piccolo.wrapper.client.component.JSNI;

import com.google.gwt.core.client.JsArray;
import com.piccolo.wrapper.client.component.PBounds;
import com.piccolo.wrapper.client.component.Overlay.PBoundsOverlay;
import com.piccolo.wrapper.client.component.Overlay.PCanvasOverlay;
import com.piccolo.wrapper.client.component.Overlay.PNodeOverlay;
import com.piccolo.wrapper.client.component.Overlay.PPointOverlay;
import com.piccolo.wrapper.client.component.Overlay.PRootOverlay;
import com.piccolo.wrapper.client.component.Overlay.PTransformOverlay;
import com.piccolo.wrapper.client.handler.PBasicInputEventHandler;

public class PNodeJSNI 
{
	public native PNodeOverlay create(String theStyle, PBoundsOverlay theBounds) 
	/*-{ return new $wnd.PNode({fillStyle: theStyle, bounds: theBounds}); }-*/ ;

	public native PNodeOverlay create() 
	/*-{ return new $wnd.PNode(); }-*/ ;

	public native JsArray<PNodeOverlay> getChildren(PNodeOverlay self) 
	/*-{ return self.children; }-*/ ;

	public native void addChild(PNodeOverlay self, PNodeOverlay child) 
	/*-{ self.addChild(child); }-*/;
	
	public native void scale(PNodeOverlay self, double d) 
	/*-{ self.scale(d); }-*/;
	
	public native void translate(PNodeOverlay self, double x, double y) 
	/*-{ self.translate(x, y); }-*/;

	public native void setDisplayScale(PNodeOverlay self, double theScale)
	/*-{ self.displayScale = theScale; }-*/ ;
	
	public native double getDisplayScale(PNodeOverlay self)
	/*-{ return self.getScale(); }-*/;

	public native PTransformOverlay getGlobalTransform(PNodeOverlay self) 
	/*-{ return self.getGlobalTransform(); }-*/ ;

	public native PBoundsOverlay getGlobalFullBounds(PNodeOverlay self)
	/*-{ return self.getGlobalFullBounds(); }-*/ ;

	public native void addClickListener(PNodeOverlay self, PBasicInputEventHandler handler)
	/*-{ self.addListener({ 
	 click: function(event) 
	 {
	 	var node = event.pickedNodes[event.pickedNodes.length - 1];
	 	var pnode = @com.piccolo.wrapper.client.component.PNode::new(Lcom/piccolo/wrapper/client/component/Overlay/PNodeOverlay;)(node);
	 	var inputevent = @com.piccolo.wrapper.client.event.PInputEvent::new(Lcom/piccolo/wrapper/client/component/PNode;)(pnode);
		handler.@com.piccolo.wrapper.client.handler.PBasicInputEventHandler::mouseClicked(Lcom/piccolo/wrapper/client/event/PInputEvent;)(inputevent);
		event.cancel();
	 }});
	}-*/ ;

	public native void addMouseOverListener(PNodeOverlay self, PBasicInputEventHandler handler)
	/*-{ self.addListener({ 
	 mouseover: function(event) 
	 {
	 	var node = event.pickedNodes[event.pickedNodes.length - 1];
	 	var pnode = @com.piccolo.wrapper.client.component.PNode::new(Lcom/piccolo/wrapper/client/component/Overlay/PNodeOverlay;)(node);
	 	var inputevent = @com.piccolo.wrapper.client.event.PInputEvent::new(Lcom/piccolo/wrapper/client/component/PNode;)(pnode);
		handler.@com.piccolo.wrapper.client.handler.PBasicInputEventHandler::mouseClicked(Lcom/piccolo/wrapper/client/event/PInputEvent;)(inputevent);
		event.cancel();
	 }});
	}-*/ ;
	
	public native void addMouseOutListener(PNodeOverlay self, PBasicInputEventHandler handler)
	/*-{ self.addListener({ 
	 mouseout: function(event) 
	 {
	 	var node = event.pickedNodes[0];
	 	var pnode = @com.piccolo.wrapper.client.component.PNode::new(Lcom/piccolo/wrapper/client/component/Overlay/PNodeOverlay;)(node);
	 	var event = @com.piccolo.wrapper.client.event.PInputEvent::new(Lcom/piccolo/wrapper/client/component/PNode;)(pnode);
		handler.@com.piccolo.wrapper.client.handler.PBasicInputEventHandler::mouseClicked(Lcom/piccolo/wrapper/client/event/PInputEvent;)(event);
	 }});
	}-*/ ;
	
	public native void paintAfterChildren(PNodeOverlay self, PCanvasOverlay canvas) 
	/*-{ self.paintAfterChildren(context, canvas.getContext('2d')); }-*/;

	public native PBoundsOverlay getBounds(PNodeOverlay self) 	
	/*-{ return self.bounds; }-*/;

	public native void rotate(PNodeOverlay self, double theta) 
	/*-{ self.rotate(theta); }-*/;
	
	public native void setTransform(PNodeOverlay self, PTransformOverlay transformation) 
	/*-{ self.setTransform(transformation); }-*/;
	
	public native PRootOverlay getRoot(PNodeOverlay self) 
	/*-{ return self.getRoot(); }-*/;
	
	public native void setBounds(PNodeOverlay sef, PBoundsOverlay bounds)
	/*-{ return self.bounds = bounds; }-*/;

	public native void removeChild(PNodeOverlay self, PNodeOverlay child) 
	/*-{ self.removeChild(child); }-*/;
	
	public native void animateToTransform(PNodeOverlay self, PTransformOverlay target, double duration) 
	/*-{ self.animateToTransform(target, duration); }-*/;

	public native PBoundsOverlay getFullBounds(PNodeOverlay self) 
	/*-{ return self.getFullBounds(); }-*/;

	public native void invalidateBounds(PNodeOverlay self) 
	/*-{ self.invalidateBounds(); }-*/;

	public native PTransformOverlay localToParent(PNodeOverlay self, PTransformOverlay target) 
	/*-{ return self.localToParent(target); }-*/;

	public native PPointOverlay localToParent(PNodeOverlay self, PPointOverlay target) 
	/*-{ return self.localToParent(target); }-*/;
	
	public native PBounds localToParent(PNodeOverlay self, PBoundsOverlay target) 
	/*-{ return self.localToParent(target); }-*/;

	public native PTransformOverlay parentToLocal(PNodeOverlay self, PTransformOverlay target) 
	/*-{ return self.parentToLocal(target); }-*/;

	public native PPointOverlay parentToLocal(PNodeOverlay self, PPointOverlay target) 
	/*-{ return self.parentToLocal(target); }-*/;

	public native PBounds parentToLocal(PNodeOverlay self,	PBoundsOverlay target) 
	/*-{ return self.parentToLocal(target); }-*/;

	public native void moveToFront(PNodeOverlay self) 
	/*-{ self.moveToFront(); }-*/;

	public native void moveToBack(PNodeOverlay self) 
	/*-{ self.moveToBack(); }-*/;
}
